package com.ucombuy.getaway.filter;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by yaosheng on 2021/3/12.
 * 检验请求中的Token
 */
@Slf4j
@Component
public class TokenFilter extends AbstractPreZuulFilter{

    @Override
    protected Object cRun() {

        HttpServletRequest request = context.getRequest ();
        log.info (String.format ("%s Request to %s",request.getMethod (),request.getRequestURI ().toString ()));
        String token = request.getParameter ("token");
        if(token == null){
            log.error ("error : token is empty");
            return fail (401,"error : token is empty");
        }
        return Success ();
    }

    @Override
    public int filterOrder() {
        return 1;
    }
}
